package com.um.swing.bean;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.util.HashMap;
import java.util.Map;

/**
 * 名称：点位配置信息基类
 * 创建人：袁泉
 * 创建时间：2022年05月12日22:59:50
 */
@JsonIgnoreProperties(value = {"posSettingList","postionSettingList"})
public class BaseConfigPostionSetBean {
    protected Map<String, ConfigPostionSetBean> postionSetMap;

    public Map<String, ConfigPostionSetBean> getPostionSetMap() {
        return postionSetMap;
    }

    public void setPostionSetMap(Map<String, ConfigPostionSetBean> postionSetMap) {
        this.postionSetMap = postionSetMap;
    }

    @JsonIgnore
    public int getPostionSettingMapSize() {
        if (this.postionSetMap == null) {
            return 0;
        }
        return postionSetMap.size();
    }

    @JsonIgnore
    public void putPosSettingItem(String key, ConfigPostionSetBean set) {
        if (this.postionSetMap == null) {
            this.postionSetMap = new HashMap<>();
        }
        this.postionSetMap.put(key, set);
    }

    @JsonIgnore
    public void putPosSettingItem(int index, ConfigPostionSetBean set) {
        putPosSettingItem(getIndexKey(index), set);
    }

    private String getIndexKey(int index) {
        return "p" + index;
    }

    @JsonIgnore
    public ConfigPostionSetBean getPosSettingItem(String key) {
        if (this.postionSetMap == null) {
            return null;
        }
        return this.postionSetMap.get(key);
    }

    @JsonIgnore
    public ConfigPostionSetBean getPosSettingItem(int index) {
        if (this.postionSetMap == null) {
            return null;
        }
        return this.postionSetMap.get(getIndexKey(index));
    }
}
